package com.hnkywl.jip.action;

import com.google.gson.Gson;
import com.hnkywl.jip.service.BankService;
import com.hnkywl.jip.service.CompanyService;
import com.hnkywl.jip.utils.BankData;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ZHUCHG
 * Date: 13-3-4
 * Time: 下午4:10
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/cfg")
public class BankAction extends SimpleActionSupport {
    private Integer companyId;
    private String data;

    private List<Object[]> companyList;

    private List<Object[]> gridResult;

    private CompanyService companyService;

    private BankService bankService;

    @Action("bank_mapping")
    public String bankMapping() {
        this.companyList = this.companyService.searchAllCompany();
        return SUCCESS;
    }

    @Action("bank_grid_json")
    public String bankGridJson() {
        if (companyId != null)
            gridResult = this.bankService.searchBankMapping(companyId);
        return SUCCESS;
    }

    @Action("save_bank_grid")
    public void saveBankGrid() {
        Gson gson = new Gson();
        java.lang.reflect.Type type = new com.google.gson.reflect.TypeToken<List<BankData>>() {
        }.getType();
        List<BankData> bankDataList = gson.fromJson(this.data, type);
        this.bankService.saveBankMapping(bankDataList);
    }

    public List<Object[]> getCompanyList() {
        return companyList;
    }

    public List<Object[]> getGridResult() {
        return gridResult;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }

    public void setData(String data) {
        this.data = data;
    }

    @Autowired
    public void setCompanyService(CompanyService companyService) {
        this.companyService = companyService;
    }

    @Autowired
    public void setBankService(BankService bankService) {
        this.bankService = bankService;
    }
}
